package basicx.oop.oc

import org.eliza.base.contantx.Advise
import org.eliza.base.contantx.Name
import org.eliza.base.contantx.YouAre

/*-*- coding:utf-8 -*-
* @Author  : ygree 
* @Time    : 2021/6/29 21:01
* @Software : IntelliJ IDEA
*/

// 接口是事物的能力
// 抽象类是事物的本质
// 接口
private interface IBiological {
    abstract fun sleep() //  未实现
    fun eat() {
        println("生物需要获取能量")
    }

    fun genitals() {
        print("生物的繁殖")
    }
}

// 抽象类
private abstract class APeople : IBiological {
    abstract override fun sleep() // 未实现
    override fun eat() { // 未重写
        println("APeople eat ${Advise.random()}")
    }

    override fun genitals() {
        println("APeople genitals ${YouAre.random()}")

    }
}

private open class Father(name: String) : APeople(), IBiological {
    // open 允许继承或重写
    var name: String = name
    var time: Int = 1

    // 重写了两个方法，优先使用 //就近原则
    override fun sleep() {
        println("Father sleep $name:$time ")
    }

    override fun genitals() {
        println("Father genitals $name:$time ")
    }
}

// 继承,
private class Children(name: String) : Father(name) {
    // 具有少数主构造函数参数的类可以写成一行：
    override fun sleep() {
        println("Children sleep $name ${Advise.random()}")
    }
}

private  fun main() {
    var father = Father(name = "AA")
    father.time = 1
    father.eat() //father 未重写eat，使用就近实现
    father.genitals()
    father.time++
    father.sleep()

    println("-------children------")
    var children01 = Children(name = Name("tw")) // 继承父类，具有父类的属性和方法
    children01.sleep() // 没有进行赋值，结果为默认值
    children01.sleep() // 子类重写之后，调用默认为 重写之后的方法
    father.sleep()
}
